package com.stellar.circle.controller.miniApp.sPostLike;

import com.google.common.base.Preconditions;
import com.stellar.circle.controller.admin.sPostLike.vo.SPostLikeRequestPageVO;
import com.stellar.circle.controller.admin.sPostLike.vo.SPostLikeRequestVO;
import com.stellar.circle.controller.admin.sPostLike.vo.SPostLikeResponseVO;
import com.stellar.circle.domain.sPostLike.SPostLikeDomainService;
import com.stellar.web.core.bean.PageResult;
import com.stellar.web.core.bean.Result;
import com.stellar.web.core.constants.AuthUserConstants;
import com.stellar.web.core.validator.ValidatorRole;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 帖子点赞表控制器
 *
 * @author Jqchan
 * @version 1.0
 * @date 2025-05-19 14:23:03
 */
@RequestMapping("/api-miniApp/sPostLike")
@RestController("miniAppSPostLikeController")
@Slf4j
public class SPostLikeController {

    @Resource
    private SPostLikeDomainService sPostLikeDomainService;


    /**
     * 点赞 - 逻辑待优化
     * 当前方案：统一入库，变更帖子点赞数 V1.0
     * 优化方案：去除帖子点赞数字段，帖子点赞数由点赞表统计，点赞时不直接入库，统一入缓存，定时任务刷入库做持久化操作 V2.0
     */
    @ValidatorRole(value = {AuthUserConstants.SUPER_ADMIN, AuthUserConstants.SCHOOL_ADMIN, AuthUserConstants.NORMAL_USER})
    @PostMapping("/like")
    public Result<Boolean> like(@RequestParam("postId") Long postId) {
        try {
            if (log.isInfoEnabled()) {
                Preconditions.checkNotNull(postId, "帖子Id不能为空");
            }
            Boolean result = sPostLikeDomainService.like(postId);
            if (!result) return Result.fail(result);
            return Result.success(result);
        } catch (IllegalArgumentException iae) {
            log.error("SPostLikeController.like.error:{}", iae.getMessage());
            return Result.fail(iae.getMessage());
        }

    }
}
